package com.atguigu.utils;

import com.atguigu.bean.User;
import org.junit.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * Date:2020/8/28
 * Author:ybc
 * Description:
 */
public class JDBCUtilsTest {

    @Test
    public void testJDBCUtils(){
        Connection connection = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        List<User> list = new ArrayList<>();
        try {
            connection = JDBCUtils.getConnection();
            ps = connection.prepareStatement("select * from t_user");
            rs = ps.executeQuery();
            while(rs.next()){
                User user = new User(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getInt(5));
                list.add(user);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JDBCUtils.closeConnection(connection);
        }
        for (User user : list) {
            System.out.println(user);
        }
    }

}
